

<input type="hidden" id="cate1" value='<?php echo !empty($info) ? $info->cate_1 :"";?>'/>
<script>

    $(function () {
        var a = $, f = layui.form, tpl = layui.laytpl, ly = layui.layer,
            cate1 = a('#cate1').val(),
            util = layui.util, t = layui.table,
            ele = layui.element, iconThis = '', iconThisType = 'batch-table';

   

        if (cate1) renderCate2(a("#cate_2"), cate1);

        f.on('submit(saveProduct)', function (data) {
            var form = f.val('form'), btn = $(this);
           
            btn.attr('disabled', true);
            a.post("{:url('saveProduct')}", form, function (d) {
                if (d.code === 1) {
                    ly.msg(d.msg, {time: 1000}, function () {
                        parent.layer.closeAll();
                        window.location.href = "{:url('merchant/shop_index')}";
                    })
                } else {
                    ly.msg(d.msg);
                }
            });
            return false;
        });

        f.on('select(cate_1)', function (data) {
            console.log(111)
            if (data.value) {
                renderCate2(a("#cate_2"), data.value);
            } else {
                a("#cate_2").html('<option value="">请选择</option>');
                f.render();
            }
        });

        function renderCate2(obj, id) {
            a.get("{:url('merchant/getCateSelect')}", {id: id}, function (data) {
                var options = '<option value="">请选择</option>';
                a.each(data, function (i) {
                    var selected = obj.attr('data-id') == data[i]['id'] ? 'selected' : '';
                    options += '<option value="' + data[i]['id'] + '" ' + selected + '>' + data[i]['title'] + '</option>';
                })
                obj.html(options);
                f.render();
            })
        }

    });
</script>